home *** CD-ROM | disk | FTP | other *** search
/ Space & Astronomy / Space and Astronomy (October 1993).iso / mac / programs / satrack / SS4EXE.ZIP / SEESAT4.ZIP / SEESAT.H < prev    next >
Text File  |  1992-01-05  |  12KB  |  550 lines

  1. /*
  2. SEESAT.H
  3. by Paul S. Hirose, 1992 Jan 4
  4. Declarations & definitions for globals in the SEESAT satellite tracking
  5. program.
  6.  
  7. This file is in the public domain.
  8. */
  9.  
  10. /* If MAIN is defined, this header will generate definitions.  Otherwise,
  11. only declarations will be generated. */
  12.  
  13. #ifdef MAIN        /* generate DEFINITIONS */
  14. #define CLASS
  15. #define EQUALS(N) = N
  16.  
  17. #else            /* generate DECLARATIONS */
  18. #define CLASS extern
  19. #define EQUALS(N)
  20. #endif
  21.  
  22.  
  23. CLASS char vers[] EQUALS("1992 Jan 4");
  24.  
  25.  
  26.  
  27. /*
  28. Miscellaneous Dependencies
  29.  
  30. If your compiler is on the list below, you should be able to compile by
  31. simply setting the appropriate #define.
  32.  
  33. STDC = Standard C
  34. ECOC = Ecosoft C 3.5 for CP/M
  35. LASERC = Laser C for Atari ST
  36. TURBOC = Turbo C for MS-DOS
  37. */
  38.  
  39. #define STDC 0
  40. #define ECOC 1
  41. #define LASERC 0
  42. #define TURBOC 0
  43.  
  44. #if TURBOC
  45. #define STDC 1
  46. #endif
  47.  
  48. #include <stdio.h>
  49.  
  50. #if STDC
  51. #include <ctype.h>
  52. #include <math.h>
  53. #include <setjmp.h>
  54. #include <stdlib.h>
  55. #include <string.h>
  56. #endif
  57.  
  58. #if LASERC
  59. #include <ctype.h>
  60. #include <math.h>
  61. #include <strings.h>
  62. extern double atof(), log10();
  63. #endif
  64.  
  65. /* CP/M has to use SGP to keep size down.  Everyone else gets to use SGP4.
  66. If you want to use SGP, you'll need to get my code for sgp().  I don't
  67. distribute it as part of the normal SEESAT package, but it is available
  68. on request. */
  69.  
  70. #if ECOC
  71. #define MODEL(t) sgp(t)
  72. extern void sgp();
  73. #else
  74. #define MODEL(t) sgp4(t)
  75. extern void sgp4();
  76. #endif
  77.  
  78.  
  79. /* POW(x, y) raises x to the y power.  Both args are type double. */
  80.  
  81. #if STDC | ECOC
  82. #define POW(x, y) pow(x, y)
  83. extern double pow();
  84. #endif
  85.  
  86. #if LASERC
  87. #define POW(x, y) powerd(x, y)
  88. #endif
  89.  
  90. /* ITOA(s, i) turns int i to a string at the location pointed
  91. to by char pointer s.  The return value from ITOA() is not used. */
  92.  
  93. #if STDC | LASERC
  94. #define ITOA(s, i) sprintf(s, "%d", i)
  95. #endif
  96.  
  97. #if ECOC
  98. #define ITOA(s, i) itoa(s, i)
  99. extern char *itoa();
  100. #endif
  101.  
  102.  
  103. /* JMPBUF defines (i.e., allocates space for) an object to be used by
  104. setjmp() and longjmp().  SETJMP() and LONGJMP() must expand to calls to the
  105. actual setjmp() and longjmp().  Here's how they're used in SEESAT:
  106.  
  107. JMPBUF s;    define s as a "jump buffer"
  108. SETJMP(s);    store return location in s
  109. LONGJMP(s, 1);    execute jump to location stored in s, return 1
  110. */
  111.  
  112. #if STDC | LASERC
  113. #define JMPBUF jmp_buf
  114. #define SETJMP(s) setjmp(s)
  115. #define LONGJMP(s, i) longjmp(s, i)
  116. #endif
  117.  
  118. #if ECOC
  119. #define JMPBUF jmp_env
  120. #define SETJMP(s) setjmp(&s)
  121. #define LONGJMP(s, i) longjmp(&s, i)
  122. extern void longjmp();
  123. #endif
  124.  
  125. /* Nonzero enables precession correction to R.A./dec.  Zero will eliminate
  126. all precession code. */
  127. #define ENPRE 1
  128.  
  129. /* MALLOC(n) returns a pointer to n bytes of storage, or NULL if insufficient
  130. storage available.  It need not clear the storage it allocates. */
  131.  
  132. #if STDC | LASERC
  133. #define MALLOC(n) malloc(n)
  134. #endif
  135.  
  136. #if ECOC
  137. #define MALLOC(n) alloc(n)
  138. #endif
  139.  
  140.  
  141. /* VOIDP is the type of arg required by free(). */
  142.  
  143. #if STDC | ECOC
  144. #define VOIDP void *
  145. #endif
  146.  
  147. #if LASERC
  148. #define VOIDP char *
  149. #endif
  150.  
  151.  
  152. /* FABS(x) returns the absolute value of double x */
  153.  
  154. #if STDC | ECOC
  155. #define FABS(x) fabs(x)
  156. extern double fabs();
  157. #endif
  158.  
  159. #if LASERC
  160. #define FABS(x) dabs(x)
  161. #endif
  162.  
  163.  
  164. #if LASERC
  165. #ifdef MAIN
  166.  
  167. double atan2(y, x)
  168. double x, y;
  169. /* convert rectangular coordinates to polar, return angle (-pi to pi) */
  170. {
  171.     double a;
  172.     extern double pi;
  173.  
  174.     a = atan(y / x);
  175.     if (x < 0.)
  176.         if (y < 0.)        /* 3rd quadrant */
  177.             a -= pi;
  178.         else            /* 2nd quadrant */
  179.             a += pi;
  180.     return a;
  181. }
  182. #else
  183. extern double atan2();
  184. #endif
  185. #endif
  186.  
  187.  
  188.  
  189. /*
  190. Mathematical Constants
  191. */
  192.  
  193. CLASS double
  194.     pi EQUALS(3.141592653589793),
  195.     e6a EQUALS(1e-6),
  196.     pio2 EQUALS(1.570796326794897),        /* pi/2 */
  197.     tothrd EQUALS(.6666666666666667),    /* 2/3 */
  198.     twopi EQUALS(6.283185307179586),    /* 2pi */
  199.     x3pio2 EQUALS(4.712388980384690),    /* 3pi/2 */
  200.     de2ra EQUALS(.0174532925199433),    /* radians per degree */
  201.     ra2de EQUALS(57.29577951308232);    /* deg per radian */
  202.  
  203.  
  204.  
  205.  
  206. /*
  207. Physical Constants
  208. */
  209.  
  210. /* dimensions & gravity of earth, World Geodetic System 1972 values */
  211.  
  212. CLASS double
  213. xj2 EQUALS(1.082616e-3),    /* 2nd gravitational zonal harmonic */
  214. xj3,                /* xj3, xj4 initialized at run time */
  215. xj4,
  216. ck2 EQUALS(5.41308E-4),        /* .5 * xj2 */
  217. ck4 EQUALS(6.2098875E-7),    /* -.375 * xj4 */
  218. xke EQUALS(.743669161e-1),    /* = (G*M)^(1/2)*(er/min)^(3/2) where G =
  219.                 Newton's grav const, M = earth mass */
  220.  
  221. xkmper EQUALS(6378.135),    /* equatorial earth radius, km */
  222. mean_r EQUALS(.998882406),    /* mean radius, in units of xkmper */
  223.  
  224. /* SGP4/SGP8 density constants.  qoms2t = ((qo - so) / xkmper) ** 4,
  225. s = 1 + so / xkmper, where qo = 120 and so = 78 */
  226.  
  227. qoms2t EQUALS(1.88027916E-9),
  228. s EQUALS(1.01222928),
  229.  
  230. xmnpda EQUALS(1440.0);        /* time units/day */
  231.  
  232.  
  233.  
  234.  
  235. /*
  236. Units & Conventions
  237.  
  238. Unless the otherwise indicated, throughout this program
  239. quantities are measured in the following units:
  240.  
  241. time interval        minutes
  242. epoch            minutes since 4713 B.C. Jan 1 12h UT Julian
  243.             proleptic calendar
  244. angle            radians
  245. length            equatorial earth radii (1 unit = xkmper km)
  246.  
  247. South latitudes are negative.
  248. East longitude is positive, west negative.
  249. Azimuth is measured starting at north, increasing east.
  250. */
  251.  
  252.  
  253.  
  254.  
  255. /*
  256. Structures
  257. */
  258.  
  259. /* when converted to spherical coordinates the members become e.g. azimuth,
  260. elevation, range, respectively */
  261.  
  262. struct vector {
  263.     double x, y, z;
  264. };
  265.  
  266.  
  267. /* Julian date, time struct.  CAUTION:  jd is the jd at 12h, while time is
  268. measured from 0h, 12h before.  I.e., if s is a jdtim struct, you must
  269. convert to epoch in minutes by doing:  s.jd * 1440. + s.time - 720. */
  270.  
  271. struct jdtim {
  272.     long int jd;    /* Julian date @ 12h */
  273.     double time;    /* minutes since 0h */
  274. };
  275.  
  276.  
  277.  
  278.  
  279. /*
  280. Global Data
  281. */
  282.  
  283. CLASS double
  284.     /* satellite's orbital elements. */
  285.     xmo,    /* mean anomaly */
  286.     xnodeo,    /* right ascension of ascending node */
  287.     omegao,    /* argument of the perigee */
  288.     eo,    /* eccentricity */
  289.     xincl,    /* inclination */
  290.     xno,    /* mean motion, radians/min */
  291.     xndt2o,    /* 1st time derivative of mean motion, or ballistic
  292.         coefficient (depending on ephemeris type) */
  293.     xndd6o, /* 2nd time derivative of mean motion */
  294.     bstar,    /* BSTAR drag term if GP4 theory was used;
  295.         otherwise, radiation pressure coefficient */
  296.     epoch,    /* epoch of elements */
  297.     abmag,    /* magnitude at standard distance & illumination */
  298.  
  299.     ds50,    /* days since 1950 (only used for deep space models) */
  300.     tzone,    /* local time - UTC */
  301.     toffs;    /* value of OFFSET command */
  302.  
  303. /* Satellite geocentric position.  Generated by the prediction model. */
  304. CLASS struct vector sat;
  305.  
  306. /* The following data come from xyztop() */
  307. CLASS struct vector
  308.     azel,        /* azimuth, elevation, slant range */
  309.     radec,        /* Right Ascension, declination, slant range */
  310.     latlon;        /* longitude, latitude, altitude */
  311. CLASS double apmag;    /* apparent magnitude */
  312. CLASS int elsusa;    /* elev of sun above sat's horizon, degrees */
  313.  
  314. /* miscellaneous data */
  315.  
  316. CLASS JMPBUF reset;    /* LONGJMP(reset) returns you to the > prompt */
  317.  
  318. CLASS int iflag;    /* = 1 with new orbital elements,
  319.             reset to 0 by prediction model on first call */
  320.  
  321. CLASS char **tokp;    /* pointer to command line tokens */
  322.  
  323. CLASS char name[23];    /* of satellite */
  324.  
  325. CLASS char    /* flags */
  326.     aflag,        /* show data for predictions below horizon too */
  327.     gflag EQUALS('\001'),    /* if true, display long. with respect to
  328.                 Greenwich if false, long. is with respect
  329.                 to local meridian */
  330.     mflag;        /* absolute mag. was obtained from element file
  331.             or by manual input */
  332.  
  333.  
  334.  
  335.  
  336. /*
  337. Functions
  338. */
  339.  
  340.  
  341. /* ASTRO.C */
  342.  
  343. extern void dusk();
  344.     /* prints azimuth & elevation of sun at observer. */
  345.  
  346. extern double fmod2p();
  347.     /* Returns arg modulo 2pi */
  348.  
  349. extern void inpre();
  350.     /* initializes the precession rotation matrix */
  351.  
  352. extern void moon();
  353.     /* prints az, el, % of illum of moon */
  354.  
  355. extern void parall();
  356.     /* prints the parallactic angle at the sat */
  357.  
  358. extern void setep();
  359.     /* sets new terminal epoch for precession */
  360.  
  361. extern void seth();
  362.     /* set observer's height */
  363.  
  364. extern void setlat();
  365.     /* set latitude */
  366.  
  367. extern void setlon();
  368.     /* set longitude */
  369.  
  370. extern double thetag();
  371.     /* Returns Greenwich hour angle of Aries */
  372.  
  373. extern int xyztop();
  374.     /* computes topocentric coordinates of sat, return 1 if data should be
  375.     printed. */
  376.  
  377.  
  378. /* DRIVER.C */
  379.  
  380. extern void tok();
  381.     /* get next command line, tokenize it */
  382.  
  383.  
  384. /* READEL.C */
  385.  
  386. extern void aop();
  387.     /* manually input argument of perigee */
  388. extern void b();
  389.     /* manually input BSTAR */
  390. extern void ein();
  391.     /* manually input eccentricity */
  392. extern void epoc();
  393.     /* manually input epoch of elements */
  394. extern int getlin();
  395.     /* get a line from a file */
  396. extern void hfree();
  397.     /* frees all heap storage */
  398. extern void inc();
  399.     /* manually input inclination */
  400. extern void indx();
  401.     /* lists satellites in the open element file */
  402. extern void load();
  403.     /* Loads orbital elements from the open element file */
  404. extern void ma();
  405.     /* manually input mean anomaly */
  406. extern void mm();
  407.     /* manually input mean motion */
  408. extern void next();
  409.     /* load the next sat */
  410. extern void opn();
  411.     /* opens element file */
  412. extern void raan();
  413.     /* manually input Right Ascension of ascending node */
  414. extern void setact();
  415.     /* set actual time of launch */
  416. extern void setlen();
  417.     /* set max length of sat name */
  418. extern void setnam();
  419.     /* manually input sat name */
  420. extern void setnd();
  421.     /* manually input 1st derivative of mean motion */
  422. extern void setndd();
  423.     /* manually input 2nd derivative of mean motion */
  424. extern void setnom();
  425.     /* set nominal time of launch */
  426.  
  427.  
  428. /* UTIL.C */
  429.  
  430. extern double atomin();
  431.     /* convert string to minutes */
  432.  
  433. extern char **degdms();
  434.     /* convert double to deg, minutes, seconds strings */
  435.  
  436. extern char *jdstr();
  437.     /* converts jd to year, month, day in string form */
  438.  
  439. extern long int julday();
  440.     /* returns JD (unit = days) of given year, month, day @ 12h */
  441.  
  442. extern char *stoup();
  443.     /* converts sting to all upper case */
  444.  
  445. extern char *timstr();
  446.     /* converts minutes to string of "hhmm:ss" format */
  447.  
  448. extern void tokjum();
  449.     /* converts date/time group on command line to JD & minutes */
  450.  
  451. extern double tokmin();
  452.     /* converts date/time group on cmd line to epoch in minutes */
  453.  
  454.  
  455.  
  456.  
  457. /*
  458. Debugging
  459. */
  460.  
  461. /* DEBUG is controlled in the file that #includes this file. */
  462.  
  463. #ifdef DEBUG
  464. #define DTEST(a) ddebug a
  465. #define ETEST(a) edebug a
  466. #define FTEST(a) fdebug a
  467. #define STEST(a) sdebug a
  468. extern void ddebug(), edebug(), fdebug(), sdebug();
  469.  
  470. #ifdef MAIN
  471.  
  472. /* Debugging functions.  This stuff is only activated when
  473. SEESAT.C is compiled with DEBUG on.  Each function printf()s a
  474. variable number of arguments of a particular type.  If the bp
  475. argument passed to the function matches variable stopat, the
  476. arguments are printf() all on the same line.  If bp != stopat, no
  477. action occurs.  The arguments to be printed are passed by
  478. reference, and the number of arguments is given by argc. */
  479.  
  480. static int stopat;        /* currently active break point */
  481.  
  482. void
  483. ddebug(bp, argc, arg1)
  484. int bp, argc, *arg1;
  485. {
  486.     if (bp == stopat) {
  487.         int **argptr;
  488.         printf("%d: ", bp);
  489.         for (argptr = &arg1; argc ; ++argptr, --argc)
  490.             printf("%d ", **argptr);
  491.         getbp();
  492. }    }
  493.  
  494. void
  495. edebug(bp, argc, prec, arg1)
  496. int bp, argc, prec;
  497. double *arg1;
  498. {
  499.     if (bp == stopat) {
  500.         double **argptr;
  501.         printf("%d: ", bp);
  502.         for (argptr = &arg1; argc; ++argptr, --argc)
  503.             printf("%.*e ", prec, **argptr);
  504.         getbp();
  505. }    }
  506.  
  507. void
  508. fdebug(bp, argc, prec, arg1)
  509. int bp, argc, prec;
  510. double *arg1;
  511. {
  512.     if (bp == stopat) {
  513.         double **argptr;
  514.         printf("%d: ", bp);
  515.         for (argptr = &arg1; argc; ++argptr, --argc)
  516.             printf("%.*f ", prec, **argptr);
  517.         getbp();
  518. }    }
  519.  
  520. void
  521. sdebug(bp, arg)
  522. int bp;
  523. char *arg;
  524. {
  525.     if (bp == stopat) {
  526.         printf("%d: \"%s\"\n", arg);
  527.         getbp();
  528. }    }
  529.  
  530. static void
  531. getbp()
  532. /* ask for next breakpoint, put value in stopat */
  533. {
  534.     char buffer[7];
  535.     printf("\nnext breakpoint? ");
  536.     stopat = atoi(gets(buffer));
  537. }
  538.  
  539. #endif
  540.  
  541. #else
  542. /* Debugging is turned off, so expand the macros to nothing */
  543. #define DTEST(a)
  544. #define ETEST(a)
  545. #define FTEST(a)
  546. #define STEST(a)
  547.  
  548. #endif
  549. gptr = &arg1; argc ; ++argptr, --argc)
  550.             printf("%